﻿//5. You are given an array of strings. Write a method that sorts the array
//by the length of its elements (the number of characters composing them).


using System;
using System.Collections.Generic;

class SortingStrigsByTheLength
{
    static void Main()
    {
        string[] arrString =
        {
            "aha", "ahae", "ehee", "hehehe", "ehedeaha", "segade", "da", "ama"
        };
        SortingMethod(arrString);
    }

    static void SortingMethod(string[] arrString)
    {
        int[] arrStringsLength = new int[arrString.Length];
        string[] arrStringTemp = (string[]) arrString.Clone();
        for (int i = 0; i < arrString.Length; i++)
        {
            arrStringsLength[i] = arrString[i].Length;
        }
        Array.Sort(arrStringsLength);
        Array.Clear(arrString, 0, arrString.Length);
        int position = 0;
        for (int i = 0; i < arrStringsLength.Length; i++)
        {
            position = Array.BinarySearch(arrStringsLength, arrStringTemp[i].Length);
            while (arrString[position] != default(string))
            {
                position++;
            }
            arrString[position] = arrStringTemp[i];
        }
        foreach (var e in arrString)
        {
            Console.WriteLine(e);
        }
    }
}
